#pragma once
#include "../../App.h"
#include <QQmlContext>
#include "QRenderer.h"
#include "QDynQml.h"
#include "QUtil.h"
#include "../../core/cbase.h"

class QApp {// at best: only static methods and no member variants
public:
	static void init(QQuickView* view, bool is3DViewVisible = true) {/** @note visit https://doc.qt.io/qt-6/qquickwindow.html to get more signals/slots and Apis */
		App::init();

		qmlRegisterType<QRenderer>("HB.Scene3D", 1, 0, "Scene3D");
		view->rootContext()->setContextProperty("_dynqml", QDynQml::get());
		view->setSurfaceType(QSurface::OpenGLSurface);

		const bool AsIndependentApp = false;
		if (!IsEnv_Linux || AsIndependentApp) {
			view->setSource(QUrl(Config::MainQmlPath().c_str()));
			view->resize(W3D, H3D);
			//view->setPosition(100, 100);//view->setPosition(-1920, 585);
			view->create();
			view->show();
		}

		QRenderer::setItemVisible(is3DViewVisible);
	}

	/**
	* @brief print log of Qt system
	* @note call it before QApplication is created
	* @details log categories see @link https://doc.qt.io/qt-5/qtquick-visualcanvas-scenegraph.html#logging-support */
	static void enableQtEnvLog() {
		const bool Enable_QtEnvLog = false;
		if (!Enable_QtEnvLog)
			return;
		CStringList QtEnvLogCategories;
		QtEnvLogCategories << "qt.scenegraph.time.renderloop";
		QUtil::enableQtEnvLog(QtEnvLogCategories);
	}

private:
	QApp() = default;
};